public class Solution1221 {
    public int balancedStringSplit(String s) {
        int l=0,r=0,count=0;
        char[] chars=s.toCharArray();
        for (char aChar : chars) {
            if (aChar=='L'){
                l++;
            }else{
                r++;
            }
            if (l==r){
                l=r=0;
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1221().balancedStringSplit("RLRRLLRLRL"));
    }
}
